#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>
#ifndef NEW_DEMO_FRAME
#include <api/libpub29/lib_pub27.h>
#include <api/libpub29/lib_as.h>
#endif
#include <api/libosd/osd_lib.h>
//#include <lib/libui/libgui2/osd/Osd_lib.h>
#include "osdobjs_def.h"
#include "string.id"
#include "images.id"
#include "osd_config.h"

#include "menus_root.h"
#include "win_com.h"
#include "win_com_popup.h"
#include "win_com_list.h"
#include "win_signalstatus.h"

#include "control.h"

#ifdef NIM_S3501_ASCAN_TOOLS

extern UINT32 nim_s3501_ascan_get_loop_cnt();
extern void nim_s3501_ascan_set_loop_cnt(UINT32 l_cnt);
extern UINT32 nim_s3501_ascan_get_scan_tp_only();
extern void nim_s3501_ascan_set_scan_tp_only(UINT32 t_only);
extern UINT32 nim_s3501_ascan_get_freq_start();
extern void nim_s3501_ascan_set_freq_start(UINT32 f_start);
extern UINT32 nim_s3501_ascan_get_freq_end();
extern void nim_s3501_ascan_set_freq_end(UINT32 f_end);
extern UINT32 nim_s3501_ascan_get_log_onoff();
extern void nim_s3501_ascan_set_log_onoff(UINT32 on_off);
extern UINT32 nim_s3501_ascan_get_sats_idx();
extern void nim_s3501_ascan_set_sats_idx(UINT32 sel_idx);

#define ASE_PRINT	soc_printf



/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER g_win_ascan_edit,g_win_tplist;
extern OBJLIST	 tplst_olist;

extern CONTAINER ase_item1;	/* Freq start */
extern CONTAINER ase_item2;	/* Freq end*/
extern CONTAINER ase_item3;	/* scan tp only*/
extern CONTAINER ase_item4;	/* Search Mode */
extern CONTAINER ase_item5;	/* Search */
extern CONTAINER ase_item6;	/* Search */

extern TEXT_FIELD ase_title;
extern TEXT_FIELD ase_txt1;
extern TEXT_FIELD ase_txt2;
extern TEXT_FIELD ase_txt3;
extern TEXT_FIELD ase_txt4;
extern TEXT_FIELD ase_txt5;
extern TEXT_FIELD ase_txt6;
extern TEXT_FIELD ase_btntxt_ok;
extern TEXT_FIELD ase_btntxt_cancel;

extern EDIT_FIELD ase_edt1;	/* Freq */
extern EDIT_FIELD ase_edt2;	/* Symb */
extern EDIT_FIELD ase_edt3;	/* Freq */
extern EDIT_FIELD ase_edt4;	/* Symb */
extern MULTISEL   ase_msel5;	/* Pol */
extern MULTISEL   ase_msel6;	/* Search Mode */


static VACTION ase_item_edt_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT ase_item_edt_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION ase_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT ase_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION ase_item_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT ase_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION ase_btn_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT ase_btn_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


static VACTION ase_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT ase_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define WIN_SH_IDX	  WSTL_POP_WIN_01_HD
#define WIN_HL_IDX	  WSTL_POP_WIN_01_HD
#define WIN_SL_IDX	  WSTL_POP_WIN_01_HD
#define WIN_GRY_IDX  WSTL_POP_WIN_01_HD

#define CON_SH_IDX   WSTL_TEXT_04_HD
#define CON_HL_IDX   WSTL_BUTTON_05_HD
#define CON_SL_IDX   WSTL_BUTTON_01_HD
#define CON_GRY_IDX  WSTL_BUTTON_07_HD

#define TXT_SH_IDX   WSTL_TEXT_04_HD
#define TXT_HL_IDX   WSTL_BUTTON_02_FG_HD
#define TXT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define TXT_GRY_IDX  WSTL_BUTTON_07_HD

#define TTILE_SH_IDX    WSTL_POP_TXT_SH_HD
#define TTILE_HL_IDX    TTILE_SH_IDX
#define TTILE_SL_IDX    TTILE_SH_IDX
#define TTILE_GRY_IDX   TTILE_SH_IDX


#define EDT_SH_IDX   WSTL_TEXT_04_HD
#define EDT_HL_IDX   WSTL_BUTTON_04_HD//WSTL_BUTTON_08
#define EDT_SL_IDX   WSTL_BUTTON_01_FG_HD
#define EDT_GRY_IDX  WSTL_BUTTON_07_HD

#define SEL_SH_IDX   WSTL_TEXT_04_HD
#define SEL_HL_IDX   WSTL_BUTTON_04_HD
#define SEL_SL_IDX   WSTL_BUTTON_01_FG_HD
#define SEL_GRY_IDX  WSTL_BUTTON_07_HD

#define POPUPSH_IDX	WSTL_BUTTON_POP_SH_HD
#define POPUPHL_IDX	WSTL_BUTTON_POP_HL_HD

#define	W_L     324//460//150
#define	W_T     140//180//110
#define	W_W     510
#define	W_H     390


#define TITLE_L     (W_L + 20)
#define TITLE_T	    (W_T + 20)
#define TITLE_W     (W_W - 40)
#define TITLE_H     40

#define CON_L	    (W_L + 20)
#define CON_T	    (TITLE_T +  TITLE_H + 4)
#define CON_W	    (W_W - 40)
#define CON_H	    40
#define CON_GAP	    0

#define TXT_L_OF  	10
#define TXT_W  		200
#define TXT_H		40
#define TXT_T_OF	((CON_H - TXT_H)/2)

#define SEL_L_OF    (TXT_L_OF + TXT_W)
#define SEL_W  		(CON_W - TXT_W-20)
#define SEL_H		40
#define SEL_T_OF	((CON_H - SEL_H)/2)

#define BTN_L_OF	((W_W - BTN_W*2 - BTN_GAP)/2)
#define BTN_T_OF	((CON_H + CON_GAP)*6 + 14)//100
#define BTN_W		150
#define BTN_H		38
#define BTN_GAP     60

#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,hl,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,hl,CON_SL_IDX,CON_GRY_IDX,   \
    ase_item_keymap,ase_item_callback,  \
    conobj, ID,1)
    
#define LDEF_TXT(root,varTxt,nxtObj,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TXT_SH_IDX,TXT_HL_IDX,TXT_SL_IDX,TXT_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

#define LDEF_TITLE(root,varTxt,nxtObj,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, TTILE_SH_IDX,TTILE_HL_IDX,TTILE_SL_IDX,TTILE_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,resID,str)


#define LDEF_TXT_BTN(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID)		\
    DEF_TEXTFIELD(varTxt,&root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, POPUPSH_IDX,POPUPHL_IDX,POPUPSH_IDX,POPUPSH_IDX,   \
    ase_btn_keymap,ase_btn_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 0,0,resID,NULL)


#define LDEF_EDIT(root, varNum, nxtObj, ID, l, t, w, h,style,cursormode,pat,sub,str)	\
    DEF_EDITFIELD(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, EDT_SH_IDX,EDT_HL_IDX,EDT_SL_IDX,EDT_GRY_IDX,   \
    ase_item_edt_keymap,ase_item_edt_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,pat,10,cursormode,NULL,sub,str)

#define LDEF_MSEL(root, varNum, nxtObj, ID, l, t, w, h,style,cur,cnt,ptabl)	\
    DEF_MULTISEL(varNum,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,ID,ID,ID,ID, l,t,w,h, SEL_SH_IDX,SEL_HL_IDX,SEL_SL_IDX,SEL_GRY_IDX,   \
    ase_item_sel_keymap,ase_item_sel_callback,  \
    C_ALIGN_CENTER | C_ALIGN_VCENTER, 20,0,style,ptabl,cur,cnt)


#define LDEF_MENU_ITEM_EDT(root,varCon,nxtObj,varTxt,varNum,ID,IDu,IDd,\
						l,t,w,h,resID,style,curMode,pat,sub,str,str1) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID,str1)    \
    LDEF_EDIT(&varCon,varNum,NULL   ,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,curMode,pat,sub,str)

#define LDEF_MENU_ITEM_SEL(root,varCon,nxtObj,varTxt,varNum,ID,IDu,IDd,\
						l,t,w,h,resID,style,cur,cnt,ptbl,str1) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HL_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,&varNum,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID,str1)    \
    LDEF_MSEL(&varCon,varNum,NULL   ,ID, l + SEL_L_OF ,t + SEL_T_OF,SEL_W,SEL_H,style,cur,cnt,ptbl)

#define LDEF_MENU_ITEM_TXT(root,varCon,nxtObj,varTxt,ID,IDu,IDd,\
						l,t,w,h,resID,str1) \
    LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,CON_HLSUB_IDX,&varTxt,ID)   \
    LDEF_TXT(&varCon,varTxt,NULL,l + TXT_L_OF,t + TXT_T_OF,TXT_W,TXT_H,resID,str1)


#define LDEF_WIN(varCon,nxtObj,l,t,w,h,focusID)		\
    DEF_CONTAINER(varCon,NULL,NULL,C_ATTR_ACTIVE,0, \
    0,0,0,0,0, l,t,w,h, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    ase_keymap,ase_callback,  \
    nxtObj, focusID,0)

static char fre_s_pat[]  = "r900~2200";
static char fre_e_pat[]  = "r900~2200";
static char as_loop_pat[] = "r1~100";
static char sat_idx_pat[] = "r1~20";
//extern char fre_pat[] ;
//extern char symb_pat[];
static UINT16 fre_s_sub[10];
static UINT16 fre_e_sub[10];
static UINT16 as_loop_sub[10];
static UINT16 sat_idx_sub[10];
static UINT16 ase_switch_ids[]=
{
	RS_COMMON_OFF,
	RS_COMMON_ON,
};

LDEF_TITLE(g_win_ascan_edit, ase_title, &ase_item1, \
		TITLE_L, TITLE_T, TITLE_W, TITLE_H, NULL, display_strs[0])

LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item1,&ase_item2,ase_txt1,ase_edt1, 1, 7, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, fre_s_pat,fre_s_sub, display_strs[1],display_strs[2])

LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item2,&ase_item3,ase_txt2,ase_edt2, 2, 1, 3, \
		CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, fre_e_pat,fre_e_sub, display_strs[3],display_strs[4])

LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item3,&ase_item4,ase_txt3,ase_edt3, 3, 2, 4, \
		CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, as_loop_pat,as_loop_sub, display_strs[5],display_strs[6])

LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item4,&ase_item5,ase_txt4,ase_edt4, 4, 3, 5, \
		CON_L, CON_T + (CON_H + CON_GAP)*3, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, sat_idx_pat,sat_idx_sub, display_strs[7],display_strs[8])

LDEF_MENU_ITEM_SEL(g_win_ascan_edit,ase_item5,&ase_item6,ase_txt5,ase_msel5, 5, 4, 6, \
		CON_L, CON_T + (CON_H + CON_GAP)*4, CON_W, CON_H, NULL, STRING_ID, 0, 2, ase_switch_ids,display_strs[9])

LDEF_MENU_ITEM_SEL(g_win_ascan_edit,ase_item6,&ase_btntxt_ok,ase_txt6,ase_msel6, 6, 5, 7, \
		CON_L, CON_T + (CON_H + CON_GAP)*5, CON_W, CON_H, NULL, STRING_ID, 0, 2, ase_switch_ids,display_strs[10])


LDEF_TXT_BTN(g_win_ascan_edit, ase_btntxt_ok,&ase_btntxt_cancel,7,8,8,6,1,	\
			CON_L + BTN_L_OF, CON_T + BTN_T_OF, BTN_W, BTN_H, RS_COMMON_SAVE)

LDEF_TXT_BTN(g_win_ascan_edit, ase_btntxt_cancel, NULL            ,8,7,7,6,1,	\
			CON_L + BTN_L_OF + BTN_W + BTN_GAP, CON_T + BTN_T_OF, BTN_W, BTN_H, RS_COMMON_CANCEL)
			
LDEF_WIN(g_win_ascan_edit, &ase_title,W_L, W_T,W_W,W_H,1)


#ifdef    MY_TEST
LDEF_TITLE(g_win_ascan_edit, ase_title, &ase_item1, \
		TITLE_L, TITLE_T, TITLE_W, TITLE_H, NULL, display_strs[5])
LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item1,&ase_item2,ase_txt1,ase_edt1, 1, 4, 2, \
		CON_L, CON_T + (CON_H + CON_GAP)*0, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, fre_s_pat,fre_s_sub, display_strs[0],display_strs[2])
LDEF_MENU_ITEM_EDT(g_win_ascan_edit,ase_item2,&ase_item3,ase_txt2,ase_edt2, 2, 1, 3, \
		CON_L, CON_T + (CON_H + CON_GAP)*1, CON_W, CON_H, NULL, NORMAL_EDIT_MODE, CURSOR_SPECIAL, fre_e_pat,fre_e_sub, display_strs[1],display_strs[3])
LDEF_MENU_ITEM_SEL(g_win_ascan_edit,ase_item3,&ase_btntxt_ok,ase_txt3,ase_msel5, 3, 2, 4, \
		CON_L, CON_T + (CON_H + CON_GAP)*2, CON_W, CON_H, NULL, STRING_ID, 0, 2, ase_switch_ids,display_strs[4])
LDEF_TXT_BTN(g_win_ascan_edit, ase_btntxt_ok,&ase_btntxt_cancel,4,5,5,3,1,	\
			CON_L + BTN_L_OF, CON_T + BTN_T_OF, BTN_W, BTN_H, RS_COMMON_SAVE)
LDEF_TXT_BTN(g_win_ascan_edit, ase_btntxt_cancel, NULL            ,5,4,4,3,1,	\
			CON_L + BTN_L_OF + BTN_W + BTN_GAP, CON_T + BTN_T_OF, BTN_W, BTN_H, RS_COMMON_CANCEL)
			
LDEF_WIN(g_win_ascan_edit, &ase_title,W_L, W_T,W_W,W_H,1)
#endif

#define WASCAN_FREQ_START_ID		1
#define WASCAN_FREQ_END_ID		2
#define WASCAN_LOOP_CNT_ID		3
#define WASCAN_SAT_IDX_ID			4
#define WASCAN_TP_ONLY_ONOFF		5
#define WASCAN_LOG_ONOFF			6

#define BTN_OK_ID		7
#define BTN_CANCEL_ID	8
//#define TP_SRCHMODE_ID	4
//#define TP_SRCH_ID	5

/*******************************************************************************
*	Local vriable & function declare
*******************************************************************************/

UINT8  edit_ascan_ok; /* 0 - cancel : 1 save*/
//UINT8  edit_ascan_mode;
//UINT32 edit_ascan_sat_id;
//UINT32 edit_ascan_id;
UINT32 edit_ascan_exist;
//UINT8  is_ase_exist[] = "TP already exists! Select [YES] Jump exist tp,Select [NO] Continue Add";
win_popup_choice_t edit_ascan_yesno;

static void win_ase_load_setting(void);
static UINT32 win_ase_check_input(void);


/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static VACTION ase_item_edt_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
    {
	case V_KEY_0:	case V_KEY_1:	case V_KEY_2:	case V_KEY_3:
	case V_KEY_4:	case V_KEY_5:	case V_KEY_6:	case V_KEY_7:
	case V_KEY_8:	case V_KEY_9:
		act = key - V_KEY_0 + VACT_NUM_0;
		break;
	case V_KEY_LEFT:
		act = VACT_EDIT_LEFT;
		break;
	case V_KEY_RIGHT:
		act = VACT_EDIT_RIGHT;
		break;		
	default:					
		act = VACT_PASS;
	}

	return act;	 
	 
}


static PRESULT ase_item_edt_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	switch(event)
	{
	case EVN_PRE_CHANGE:
		break;
	case EVN_POST_CHANGE:
		break;
	}

	return ret;
}

static VACTION ase_item_sel_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	switch(key)
	{
  	case V_KEY_LEFT:
        act = VACT_DECREASE;
        break;
    case V_KEY_RIGHT:
        act = VACT_INCREASE;
		break;
	default:
		act = VACT_PASS;
	}

	return act;	
}

static PRESULT ase_item_sel_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	switch(event)
	{
	case EVN_PRE_CHANGE:
		break;
	case EVN_POST_CHANGE:
		break;
	}

	return ret;
}

static VACTION ase_item_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	return act;	
}

static PRESULT ase_item_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	return ret;
}

static VACTION ase_btn_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act = VACT_PASS;

	if(key == V_KEY_ENTER)
		act = VACT_ENTER;

	return act;	

}

static PRESULT ase_btn_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	bID;
    
	bID = OSD_GetObjID(pObj);
    
	switch(event)
	{
	case EVN_UNKNOWN_ACTION:
		if(bID == BTN_OK_ID)
		{	
            edit_ascan_exist = 0; 
			if((edit_ascan_exist = win_ase_check_input()) == 0)
			{
				edit_ascan_ok = 1;
				ret = PROC_LEAVE;
			}
            
            if(edit_ascan_yesno == WIN_POP_CHOICE_YES)
            {
                edit_ascan_ok = 0;
                ret = PROC_LEAVE;
            }
            else if(edit_ascan_yesno == WIN_POP_CHOICE_NO)//NO
            {
                edit_ascan_ok = 0;
                edit_ascan_exist = 0;
            }
                
            
            
		}
		else if(bID == BTN_CANCEL_ID)
			ret = PROC_LEAVE;
		
		break;
	}

	return ret;
}

static VACTION ase_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	switch(key)
	{
  	case V_KEY_UP:
        act = VACT_CURSOR_UP;
        break;
    case V_KEY_DOWN:
        act = VACT_CURSOR_DOWN;
		break;
  	case V_KEY_LEFT:
        act = VACT_CURSOR_LEFT;
        break;
    case V_KEY_RIGHT:
        act = VACT_CURSOR_RIGHT;
		break;
	case V_KEY_EXIT:
	case V_KEY_MENU:
		act = VACT_CLOSE;
		break;
	default:
		act = VACT_PASS;
	}

	return act;	

}

static PRESULT ase_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;

	switch(event)
	{
	case EVN_PRE_OPEN:
		win_ase_load_setting();		
		break;
	case EVN_POST_OPEN:
		break;
	case EVN_PRE_CLOSE:
		/* Make OSD not flickering */
		*((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;			
		break;
	case EVN_POST_CLOSE:
		break;			
	}
	
	return ret;
}


static void win_ase_load_setting(void)
{
	EDIT_FIELD	*edf;
	MULTISEL	*msel;
	T_NODE     t_node;
	UINT32 v_freq_start,v_freq_end,v_tp_only;
	UINT32 v_sel_idx,v_log_on,v_loop_cnt;
	v_freq_start=nim_s3501_ascan_get_freq_start();
	v_freq_end=nim_s3501_ascan_get_freq_end();
	v_tp_only=nim_s3501_ascan_get_scan_tp_only();
	v_sel_idx=nim_s3501_ascan_get_sats_idx();
	v_log_on=nim_s3501_ascan_get_log_onoff();
	v_loop_cnt=nim_s3501_ascan_get_loop_cnt();


	edit_ascan_ok = 0;
    edit_ascan_exist = 0;


	edf = &ase_edt1;
	OSD_SetEditFieldSuffix(edf, STRING_ANSI, (UINT32)" MHz");
	OSD_SetEditFieldContent(edf, STRING_NUMBER, v_freq_start);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);

	
	edf = &ase_edt2;
	OSD_SetEditFieldSuffix(edf, STRING_ANSI, (UINT32)" MHz");
	OSD_SetEditFieldContent(edf, STRING_NUMBER, v_freq_end);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);

	edf = &ase_edt3;
	OSD_SetEditFieldSuffix(edf, STRING_ANSI, (UINT32)" s");
	OSD_SetEditFieldContent(edf, STRING_NUMBER, v_loop_cnt);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);

	edf = &ase_edt4;
	OSD_SetEditFieldSuffix(edf, STRING_ANSI, (UINT32)" x");
	OSD_SetEditFieldContent(edf, STRING_NUMBER, v_sel_idx);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);

	msel = &ase_msel5;
	OSD_SetMultiselSel(msel, v_tp_only);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);

	msel = &ase_msel6;
	OSD_SetMultiselSel(msel, v_log_on);
	OSD_SetEditFieldStyle(edf,NORMAL_EDIT_MODE | SELECT_STATUS);
	
}

static UINT32 win_ase_check_input(void)
{
	EDIT_FIELD	*edf;
	MULTISEL	*msel;
	T_NODE     t_node;
	UINT32 freq_s,freq_e, loops,sel_idx, tp_only,log_on;
	UINT32 i,tp_cn;
	UINT8 back_saved;

    edit_ascan_yesno = WIN_POP_CHOICE_NULL;
	
	edf = &ase_edt1;
	OSD_GetEditFieldIntValue(edf, &freq_s);

	edf = &ase_edt2;
	OSD_GetEditFieldIntValue(edf, &freq_e);

	edf = &ase_edt3;
	OSD_GetEditFieldIntValue(edf, &loops);

	edf = &ase_edt4;
	OSD_GetEditFieldIntValue(edf, &sel_idx);

	msel = &ase_msel5;
	tp_only  = OSD_GetMultiselSel(msel);	

	msel = &ase_msel6;
	log_on  = OSD_GetMultiselSel(msel);

	nim_s3501_ascan_set_freq_start(freq_s);
	nim_s3501_ascan_set_freq_end(freq_e);
	nim_s3501_ascan_set_scan_tp_only(tp_only);
	nim_s3501_ascan_set_sats_idx(sel_idx);
	nim_s3501_ascan_set_log_onoff(log_on);
	nim_s3501_ascan_set_loop_cnt(loops);
	

	return 0;
}
	

UINT32 win_ase_open()
{

	CONTAINER* win;
	PRESULT ret = PROC_LOOP;
	UINT32 hkey;
	TEXT_FIELD* txt;

    BOOL old_value = ap_enable_key_task_get_key(TRUE);
	OSD_SetTextFieldContent(&ase_title,STRING_ANSI,(UINT32)"Autoscan Config");
	OSD_SetTextFieldContent(&ase_txt1,STRING_ANSI,(UINT32)"Start Freq");
	OSD_SetTextFieldContent(&ase_txt2,STRING_ANSI,(UINT32)"End Freq");
	OSD_SetTextFieldContent(&ase_txt3,STRING_ANSI,(UINT32)"Loop Cnt");
	OSD_SetTextFieldContent(&ase_txt4,STRING_ANSI,(UINT32)"Sat Idx");
	OSD_SetTextFieldContent(&ase_txt5,STRING_ANSI,(UINT32)"TP Only");
	OSD_SetTextFieldContent(&ase_txt6,STRING_ANSI,(UINT32)"Print Log");
	
	
	win = &g_win_ascan_edit;
	OSD_SetContainerFocus(win, WASCAN_FREQ_START_ID);

	OSD_ObjOpen((POBJECT_HEAD)win, 0);
	 
	while(ret != PROC_LEAVE)
	{
	    hkey = ap_get_popup_msg(C_POPUP_MSG_PASS_CI);
        if(hkey == INVALID_HK || hkey == INVALID_MSG)
            continue;

		ret = OSD_ObjProc((POBJECT_HEAD)win, (MSG_TYPE_KEY<<16),hkey, 0);
	}

    ap_enable_key_task_get_key(old_value);

	return edit_ascan_ok;	
}


void win_ase_get_setting(UINT32* freq, UINT32* symb, UINT32* pol)
{
	EDIT_FIELD	*edf;
	MULTISEL	*msel;

	
	edf = &ase_edt1;
	OSD_GetEditFieldIntValue(edf, freq);

	edf = &ase_edt2;
	OSD_GetEditFieldIntValue(edf, symb);

	msel = &ase_msel5;
	*pol  = OSD_GetMultiselSel(msel);	
}

#endif

